package com.example.hello.client.Container;

import com.example.hello.BootstrapContainer;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.Connector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapContainer.class)
public class BootstrapContainerConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapContainer.class);
    }

    @Override
    public VBootstrapContainer getWidget() {
        return (VBootstrapContainer) super.getWidget();
    }

    @Override
    public BootstrapContainerState getState() {
        return (BootstrapContainerState) super.getState();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapContainerState state = getState();

        VBootstrapContainer container = getWidget();

        for (Connector connector : state.getWidgets()) {
            container.add(((ComponentConnector) connector).getWidget());
        }
    }

}
